import {OrderStr, SpecialEffectType} from "../type/Type";
import {TriggerFactory} from "../frame/TriggerFactory";
import {UnitModel} from "../frame/apiModel/adapterModel/model3/UnitModel";
import {PlayerModel} from "../frame/apiModel/adapterModel/model4/PlayerModel";
import {UnitController} from "../controller/UnitController";
import Configer from "../frame/apiModel/config/Configer";
import {ConfigKey} from "../constant/ConfigConstant";
import {Logger} from "../frame/apiModel/config/Logger";
import {ResourceKey} from "../constant/ResourceConstant";
import {TimeController} from "../controller/TimeController";


export function attackedTrigger () {
    // const changeStateCallBack = function (this: void) {
    //     const triggerPlayer = GetTriggerPlayer();
    //     // ForceUtil.forUserForce(
    //     //     (player) => {
    //     //         SetPlayerAlliance(triggerPlayer, player, ALLIANCE_SHARED_CONTROL, false);
    //     //     }
    //     // )
    // }
    const attackCallBack = function (this: void, attacker: UnitModel, attacked: UnitModel, attackerPlayer: PlayerModel, attackedPlayer: PlayerModel) {
        const playerAlly = attackerPlayer?.isPlayerAlly(attackedPlayer);
        if (playerAlly) {
            const isNeutralInvincibilityId = attackedPlayer.isNeutralInvincibilityId();
            if (isNeutralInvincibilityId) {
                UnitController.getInstance().toEnemyTeam(attacked);
            } else {
                attacker.issueImmediateOrder(OrderStr.stop)
                return;
            }
        }
    }

    // const changeCoinCallBack = function (this: void) {
    //     const player = GetTriggerPlayer();
    // }

    TriggerFactory.getInstance().registerUnitAttacked(attackCallBack);
}